﻿cmake_minimum_required(VERSION 3.10)

project(qt_chat_demo VERSION 0.1 LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)

include_directories(${CMAKE_SOURCE_DIR}/include)

set(UI_FORMS
    ui/welcome/welcome.ui
    ui/server/serverwindow.ui
    ui/client/clientwindow.ui
)

set(UI_FORM_DIRS
    ui/welcome
    ui/server
    ui/client
)

set(WELCOME_SRC_FILES
    src/welcome/welcome.cpp
    include/welcome/welcome.h
)

set(SERVER_SRC_FILES
    src/server/serverwindow.cpp
    include/server/serverwindow.h
    src/server/serverthread.cpp
    include/server/serverthread.h
    include/server/server_class_def.h
)

set(CLIENT_SRC_FILES
    src/client/clientwindow.cpp
    include/client/clientwindow.h
    src/client/clientthread.cpp
    include/client/clientthread.h
    include/client/client_class_def.h
)

set(JSONCPP_FILES
    include/json/json.h
    include/json/json-forwards.h
    src/json/jsoncpp.cpp
)

set(UTIL_FILES
    include/utils.h
    src/utils.cpp
)

set(OPENSSL_FILES
    include/openssl/rsa.h
    include/openssl/pem.h
)

set(PROJECT_SOURCES
    src/main.cpp
    ${WELCOME_SRC_FILES}
    ${SERVER_SRC_FILES}
    ${CLIENT_SRC_FILES}
    ${UI_FORMS}
    ${JSONCPP_FILES}
    ${OPENSSL_FILES}
    ${UTIL_FILES}
    ${OPENSSL_FILES}
    include/valdefs.h
)

set(CMAKE_AUTOUIC_SEARCH_PATHS
    ${UI_FORM_DIRS}
)

add_executable(qt_chat_demo
    ${PROJECT_SOURCES}
)

target_link_directories(qt_chat_demo
    PUBLIC ${CMAKE_SOURCE_DIR}/bin/openssl
)

target_link_libraries(qt_chat_demo
    PRIVATE Qt${QT_VERSION_MAJOR}::Widgets
    wsock32
    ssl-3
    crypto-3
)

set_target_properties(qt_chat_demo PROPERTIES
    MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

install(TARGETS qt_chat_demo
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(qt_chat_demo)
endif()
